<template>
  <el-form
    ref="LinkFormRef"
    :model="LinkForm"
    :rules="LinkRules"
    label-width="120px"
  >
    <el-form-item label="联系人姓名" prop="m_name">
      <el-input v-model="LinkForm.m_name" placeholder="请输入联系人姓名" />
    </el-form-item>

    <el-form-item label="被寻人与联系人关系" prop="m_relat_l">
      <el-input
        v-model="LinkForm.m_relat_l"
        placeholder="请输入被寻人与联系人的关系"
      />
    </el-form-item>

    <el-form-item label="联系人手机" prop="m_phone">
      <el-input v-model="LinkForm.m_phone" placeholder="请输入联系人手机" />
    </el-form-item>

    <el-form-item label="联系人邮箱" prop="m_email">
      <el-input v-model="LinkForm.m_email" placeholder="请输入联系人邮箱" />
    </el-form-item>

    <el-form-item label="联系人微信" prop="m_wechat">
      <el-input v-model="LinkForm.m_wechat" placeholder="请选择联系人微信" />
    </el-form-item>

    <el-form-item label="联系人地址" prop="m_addr">
      <el-input
        v-model="LinkForm.m_addr"
        placeholder="请输入联系人地址"
        type="textarea"
      />
    </el-form-item>
    <el-form-item>
      <el-button @click="submitLink(LinkFormRef, loserId)" type="primary"
        >确定</el-button
      >
      <el-button @click="addLinkVisible = false" type="primary">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { useLoserRegist } from "@/hooks/loginForm/loserRegist";
import { ElMessage, type FormInstance } from "element-plus";
import { getCurrentInstance, inject, ref } from "vue";
const { LinkFormRef, LinkForm, LinkRules } = useLoserRegist();
const { proxy }: any = getCurrentInstance();
defineProps<{
  loserId: number;
}>();

const addLinkVisible = inject("addLinkVisible", ref(false));
const emit = defineEmits(["on-click"]);
const submitLink = async (
  formEl: FormInstance | undefined,
  loserId: number
) => {
  if (!formEl) return;
  await formEl.validate((valid) => {
    if (!valid) return;
    proxy.$http
      .post("/loser/addmans?id=" + loserId, LinkForm)
      .then((res: any) => {
        ElMessage.success(res);
        emit("on-click");
      });
  });
};
</script>
